package com.yunxi.controller.sat;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sat.pojo.SatTargetVO;
import com.yunxi.sat.service.SatTargetDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2019-07-24
 */
@RestController
@RequestMapping("/admin/sattarget")
@Api(tags = "pms:sattarget", description = "接口")
public class SatTargetController {
    private static final Logger logger = LoggerFactory.getLogger(SatTargetController.class);

    @Autowired
    SatTargetDubboService satTargetDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "渠道查询分页")
    public ApiResult page(SatTargetVO satTargetVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(satTargetDubboService.findPageByVO(satTargetVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询列表")
    public ApiResult list(SatTargetVO satTargetVO) throws Exception {
        return ResponseUtil.ok(satTargetDubboService.listByVo(satTargetVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    public ApiResult load(SatTargetVO satTargetVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(satTargetDubboService.getById(satTargetVO.getTargetId()));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody SatTargetVO satTargetVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        satTargetDubboService.saveOrUpdate(satTargetVO,loginInfo);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/listByPartner")
    @ApiOperation(value = "查询列表")
    public ApiResult listByPartner(SatTargetVO satTargetVO,@CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(satTargetDubboService.listByPartner(satTargetVO,loginInfo));
    }

    @PostMapping("/saveByPartner")
    @ApiOperation(value = "保存信息")
    public ApiResult saveByPartner(@RequestBody List<SatTargetVO> satTargetVOList, @CurrentUser LoginInfo loginInfo) throws Exception {
        satTargetDubboService.saveByPartner(satTargetVOList,loginInfo);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody List<SatTargetVO> satTargetVOList) throws Exception {
        satTargetDubboService.removeByListVo(satTargetVOList);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/factoryPage")
    @ApiOperation(value = "厂端查询分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult factoryPage(SatTargetVO satTargetVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(satTargetDubboService.factoryPage(satTargetVO, pageNum, pageSize));
    }

    @PostMapping("/newTarget")
    @ApiOperation(value = "厂端目标维护")
    public ApiResult newTarget(@RequestBody List<SatTargetVO> list) throws Exception {
        satTargetDubboService.newTarget(list);
        return ResponseUtil.ok("success");
    }

}
